# -*- coding:utf-8 -*-
# -------------------------------------------------------------------------------
# Description:  获取allure的测试结果，目的是将测试报告发送到钉钉 方便快捷
# Reference:
# Author: 安智军
# Date:   2021/12/17
# -------------------------------------------------------------------------------
import logging

from config.config import basepath




class Getallurereport:

    @staticmethod
    def get_allurereport_txt(file_path):
        '''
        获取allure生成的text报告数据
        :param file_path:
        :return:
        '''
        result_dict ={}
        try:
            # with open(file_path,'r',encoding='utf-8') as f:
            with open(file_path,'r') as f:
                for lines in f:
                    launch_name = lines.strip('\n').split(' ')[0]
                    num = lines.strip('\n').split(' ')[1]
                    result_dict.update({launch_name:num})
                return result_dict

        except Exception as e:
            logging.exception(f'文件读取异常，请查看文件是否正确，异常信息是：{str(e)}')
            return None


if __name__ == '__main__':
    file_path = basepath + '/Outputs/allure-reports/export/prometheusData.txt'
    print(Getallurereport.get_allurereport_txt(file_path))